package com.zjj.wangluo.tcp;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
import java.util.concurrent.CountDownLatch;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date
 */
public class WriteThread implements Runnable{

    private Socket socket;
    private CountDownLatch countDownLatch;

    public WriteThread(Socket socket , CountDownLatch countDownLatch){
        this.socket = socket;
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        try (
                Scanner sc = new Scanner(System.in);
                PrintWriter pw = new PrintWriter(socket.getOutputStream());
        ){
            while (true){
                System.out.println("请说：");
                String s = sc.nextLine();
                pw.println(s);
                pw.flush();

                if(s.equals("exit")){
                    break;
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            countDownLatch.countDown();
        }
    }
}
